<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>Dubbo 源码分析（一）配置 | Janyd Blog</title>
        <meta name="Description" content="Janyd Blog"><meta property="og:title" content="Dubbo 源码分析（一）配置" />
<meta property="og:description" content="本文基于 Dubbo 2.7.5 版本 Dubbo 配置概述 Dubbo 提供四种方式配置： API 配置 属性配置 XML 配置 注解配置 其中包含了许多灵活配置项： FROM schema 配置参考手册 所有配置项分为三大类，参" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://example.org/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE/" />
<meta property="article:published_time" content="2020-09-11T16:14:07+08:00" />
<meta property="article:modified_time" content="2020-09-11T16:14:07+08:00" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Dubbo 源码分析（一）配置"/>
<meta name="twitter:description" content="本文基于 Dubbo 2.7.5 版本 Dubbo 配置概述 Dubbo 提供四种方式配置： API 配置 属性配置 XML 配置 注解配置 其中包含了许多灵活配置项： FROM schema 配置参考手册 所有配置项分为三大类，参"/>
<meta name="theme-color" content="#ffffff">
<meta name="msapplication-TileColor" content="#da532c">
<link rel="canonical" href="http://example.org/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE/" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="prev" href="http://example.org/mybatis%E5%8A%A0%E8%BD%BD%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90%E4%B8%89-%E5%8A%A0%E8%BD%BDmybatis-config.xml%E5%86%85%E5%AE%B9/" /><link rel="next" href="http://example.org/dubbo-%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90%E4%BA%8C-api%E9%85%8D%E7%BD%AE%E5%BA%94%E7%94%A8/" /><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/css/style.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Dubbo 源码分析（一）配置",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "http:\/\/example.org\/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE\/"
        },"image": {
                "@type": "ImageObject",
                "url": "http:\/\/example.org\/cover.png",
                "width":  800 ,
                "height":  600 
            },"genre": "posts","keywords": "Dubbo, 源码解析","wordcount":  1013 ,
        "url": "http:\/\/example.org\/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE\/","datePublished": "2020-09-11","dateModified": "2020-09-11","publisher": {
                "@type": "Organization",
                "name": "Janyd",
                "logo": {
                "@type": "ImageObject",
                "url": "http:\/\/example.org\/logo.png",
                "width":  127 ,
                "height":  40 
                }
            },"author": {
                "@type": "Person",
                "name": "Janyd"
            },"description": ""
    }
    </script></head>
    <body><script>
            if (!window.localStorage || !window.localStorage.getItem('theme')) {window.isDark = 'dark' === 'dark';} else {
                window.isDark = (window.localStorage && window.localStorage.getItem('theme')) === 'dark';
            }
            window.isDark && document.body.classList.add('dark-theme');
        </script><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/">Janyd Blog</a>
        </div>
        <div class="menu"><a class="menu-item" href="/posts/" rel="noopener noreffer">文章</a><a class="menu-item" href="/tags/" rel="noopener noreffer">标签</a><a class="menu-item" href="/categories/" rel="noopener noreffer">分类</a><span class="menu-item">|</span>
            <a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-wrapper">
        <div class="header-container">
            <div class="header-title">
                <a href="/">Janyd Blog</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><a class="menu-item" href="/posts/" title="" rel="noopener noreffer">文章</a><a class="menu-item" href="/tags/" title="" rel="noopener noreffer">标签</a><a class="menu-item" href="/categories/" title="" rel="noopener noreffer">分类</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>

<script>
    window.desktopHeaderMode = "fixed";
    window.mobileHeaderMode = "auto";
</script>
<main class="main">
                <div class="container"><article class="page single"><h1 class="single-title animated flipInX">Dubbo 源码分析（一）配置</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="https://github.com/Janyd" title="Author" target="_blank" rel="noopener noreffer author" class="author"><i class="fas fa-user-circle fa-fw"></i>Janyd</a>
</span>&nbsp;
                    <span class="post-category">收录于<a href="/categories/dubbo">
                                <i class="far fa-folder fa-fw"></i>Dubbo
                            </a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i><time datetime=2020-09-11>2020-09-11</time>&nbsp;
                <i class="fas fa-pencil-alt fa-fw"></i>约 1013 字&nbsp;
                <i class="far fa-clock fa-fw"></i>预计阅读 3 分钟&nbsp;</div>
        </div><div class="toc" id="toc-auto">
                <h2 class="toc-title">目录</h2>
                <div class="toc-content" id="toc-content-auto"></div>
            </div>
            <div class="toc" id="toc-static">
                <details>
                    <summary>
                        <div class="toc-title">
                            <span>目录</span>
                            <span><i class="details icon fas fa-angle-down"></i></span>
                        </div>
                    </summary>
                    <div class="toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#dubbo-配置概述">Dubbo 配置概述</a></li>
    <li><a href="#dubbo-配置一览">Dubbo 配置一览</a></li>
    <li><a href="#模型api">模型API</a>
      <ul>
        <li><a href="#属性">属性</a></li>
      </ul>
    </li>
    <li><a href="#注解-parameter">注解 @Parameter</a></li>
    <li><a href="#参考链接">参考链接</a></li>
  </ul>
</nav></div>
                </details>
            </div><div class="content" id="content"><blockquote>
<p>本文基于 Dubbo 2.7.5 版本</p>
</blockquote>
<h2 id="dubbo-配置概述">Dubbo 配置概述</h2>
<p><code>Dubbo</code> 提供四种方式配置：</p>
<ul>
<li><a href="http://dubbo.apache.org/zh-cn/docs/user/configuration/api.html" target="_blank" rel="noopener noreffer"><code>API</code> 配置</a>
</li>
<li><a href="http://dubbo.apache.org/zh-cn/docs/user/configuration/properties.html" target="_blank" rel="noopener noreffer">属性配置</a>
</li>
<li><a href="http://dubbo.apache.org/zh-cn/docs/user/configuration/xml.html" target="_blank" rel="noopener noreffer"><code>XML</code> 配置</a>
</li>
<li><a href="http://dubbo.apache.org/zh-cn/docs/user/configuration/annotation.html" target="_blank" rel="noopener noreffer">注解配置</a>
</li>
</ul>
<p>其中包含了许多灵活配置项：</p>
<blockquote>
<p>FROM  <a href="http://dubbo.apache.org/zh-cn/docs/user/references/xml/introduction.html" target="_blank" rel="noopener noreffer">schema 配置参考手册</a>
<br>
所有配置项分为三大类，参见下表中的&quot;作用&rdquo; 一列。</p>
<ul>
<li>服务发现：表示该配置项用于服务的注册与发现，目的是让消费方找到提供方。</li>
<li>服务治理：表示该配置项用于治理服务间的关系，或为开发测试提供便利条件。</li>
<li>性能调优：表示该配置项用于调优性能，不同的选项对性能会产生影响。</li>
</ul>
<p>所有配置最终都将转换为 URL [3] 表示，并由服务提供方生成，经注册中心传递给消费方，各属性对应 URL 的参数，参见配置项一览表中的 &ldquo;对应URL参数&rdquo; 列。</p>
</blockquote>
<h2 id="dubbo-配置一览">Dubbo 配置一览</h2>
<p><img
        class="lazyload"
        src="/svg/loading.small.min.svg"
        data-sizes="auto"
        data-srcset="https://cdn.jsdelivr.net/gh/Janyd/blog-images/imgs/20200911165034.png,  1.5x,  2x"
        data-src=""
        alt=""
        title="" /></p>
<p>各个 Config 关系如下<br>
<img
        class="lazyload"
        src="/svg/loading.small.min.svg"
        data-sizes="auto"
        data-srcset="https://cdn.jsdelivr.net/gh/Janyd/blog-images/imgs/20200911165514.png,  1.5x,  2x"
        data-src=""
        alt=""
        title="" /><br>
分为4个部分：</p>
<ul>
<li>provider-side ：<code>AbstractServiceConfig</code>、<code>ProviderConfig</code>、<code>ServiceConfigBase</code>、<code>ServiceConfig</code>、<code>ServiceBean</code>、<code>ProtocolConfig</code></li>
<li>application-shared：<code>MonitorConfig</code>、<code>ModuleConfig</code>、<code>ApplicationConfig</code>、<code>RegistryConfig</code>、<code>MetricsConfig</code></li>
<li>consumer-side：<code>AbstractReferenceConfig</code>、<code>ConsumerConfig</code>、<code>ReferenceConfigBase</code>、<code>ReferenceConfig</code>、<code>ReferenceBean</code></li>
<li>sub-config：<code>AbstractMethodConfig</code>、<code>AbstractInterfaceConfig</code>、<code>MethodConfig</code>、<code>ArgumentConfig</code></li>
</ul>
<h2 id="模型api">模型API</h2>
<p><code>org.apache.dubbo.common.URL</code>，所有配置类最终会转成<code>URL</code>对象，并且由提供者生成经注册中心传递给消费者。</p>
<h3 id="属性">属性</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">URL</span> <span class="kd">implements</span> <span class="n">Serializable</span> <span class="o">{</span>

    <span class="cm">/**
</span><span class="cm">     * 协议
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">protocol</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 用户名
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">username</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 密码
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">password</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 主机地址
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">host</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 主机端口
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">port</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 路径（服务名）
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">path</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 参数集合
</span><span class="cm">     */</span>
    <span class="kd">private</span> <span class="kd">final</span> <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">parameters</span><span class="o">;</span>

<span class="c1">//省略...
</span><span class="c1"></span><span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="注解-parameter">注解 @Parameter</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-java" data-lang="java"><span class="nd">@Documented</span>
<span class="nd">@Retention</span><span class="o">(</span><span class="n">RetentionPolicy</span><span class="o">.</span><span class="na">RUNTIME</span><span class="o">)</span>
<span class="nd">@Target</span><span class="o">({</span><span class="n">ElementType</span><span class="o">.</span><span class="na">METHOD</span><span class="o">})</span>
<span class="kd">public</span> <span class="nd">@interface</span> <span class="n">Parameter</span> <span class="o">{</span>

    <span class="cm">/**
</span><span class="cm">     * 配置项名称
</span><span class="cm">     */</span>
    <span class="n">String</span> <span class="nf">key</span><span class="o">()</span> <span class="k">default</span> <span class="s">&#34;&#34;</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 是否必须要求
</span><span class="cm">     */</span>
    <span class="kt">boolean</span> <span class="nf">required</span><span class="o">()</span> <span class="k">default</span> <span class="kc">false</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 是否忽略
</span><span class="cm">     */</span>
    <span class="kt">boolean</span> <span class="nf">excluded</span><span class="o">()</span> <span class="k">default</span> <span class="kc">false</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 是否需要将配置项进行转义
</span><span class="cm">     */</span>
    <span class="kt">boolean</span> <span class="nf">escaped</span><span class="o">()</span> <span class="k">default</span> <span class="kc">false</span><span class="o">;</span>

    <span class="cm">/** 
</span><span class="cm">     * 是否为属性
</span><span class="cm">     */</span>
    <span class="kt">boolean</span> <span class="nf">attribute</span><span class="o">()</span> <span class="k">default</span> <span class="kc">false</span><span class="o">;</span>

    <span class="cm">/**
</span><span class="cm">     * 是否拼接默认属性
</span><span class="cm">     */</span>
    <span class="kt">boolean</span> <span class="nf">append</span><span class="o">()</span> <span class="k">default</span> <span class="kc">false</span><span class="o">;</span>

    <span class="kt">boolean</span> <span class="nf">useKeyAsProperty</span><span class="o">()</span> <span class="k">default</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="参考链接">参考链接</h2>
<p><a href="http://dubbo.apache.org/zh-cn/docs/user/references/api.html" target="_blank" rel="noopener noreffer">Dubbo API 参考手册</a>
</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>本文于 2020-09-11 更新</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="http://example.org/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE/" data-title="Dubbo 源码分析（一）配置"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="http://example.org/dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B8%80-%E9%85%8D%E7%BD%AE/" data-title="Dubbo 源码分析（一）配置"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/dubbo">Dubbo</a>,&nbsp;<a href="/tags/%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90">源码解析</a></section>
        <section>
            <span><a href="javascript:window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/mybatis%E5%8A%A0%E8%BD%BD%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90%E4%B8%89-%E5%8A%A0%E8%BD%BDmybatis-config.xml%E5%86%85%E5%AE%B9/" class="prev" rel="prev" title="Mybatis加载流程分析(三) - 加载mybatis-config.xml内容"><i class="fas fa-angle-left fa-fw"></i>Mybatis加载流程分析(三) - 加载mybatis-config.xml内容</a>
            <a href="/dubbo-%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90%E4%BA%8C-api%E9%85%8D%E7%BD%AE%E5%BA%94%E7%94%A8/" class="next" rel="next" title="Dubbo 源码解析（二）  API配置（应用）">Dubbo 源码解析（二）  API配置（应用）<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div class="comment"></div>
    </article></div>
            </main><footer class="footer">
    <div class="copyright"><div class="copyright-line">由 <a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreffer">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="external nofollow noopener noreffer"><i class="far fa-heart fa-fw"></i> LoveIt</a>
        </div>

        <div class="copyright-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2020</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="https://github.com/Janyd" target="_blank">Janyd</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span></div>
    </div>
</footer>
</div><a href="#" class="dynamic-to-top animated faster" id="dynamic-to-top">
            <i class="fas fa-chevron-up fa-fw"></i>
        </a><script>
        document.addEventListener('DOMContentLoaded', function () {
            lightGallery(document.getElementById('content'), {
                selector: '.lightgallery',
                speed: 400,
                hideBarsDelay: 2000,
                thumbnail: true,
                exThumbImage: 'data-thumbnail',
                thumbWidth: 80,
                thumbContHeight: 80,
            });
        });
    </script><link rel="stylesheet" href="/lib/lightgallery/lightgallery.min.css"><script src="/lib/smooth-scroll/smooth-scroll.polyfills.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/lightgallery/lightgallery.min.js"></script><script src="/lib/lightgallery/lg-thumbnail.min.js"></script><script src="/lib/lightgallery/lg-zoom.min.js"></script><script src="/js/theme.min.js"></script></body>
</html>
